<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/6/4
 * Time: 15:33
 */
namespace Controller;
use Model\IndexModel;
use Shop\Controller;

if(!defined('SHOP')){
    header("Location:/index.php");
}

class MemberController extends TooController{
    public function __construct()
    {
        parent::__construct();

        if(!$_SESSION['Home']['Member']['id']){
            header("Location:/index.php?C=Login&F=login");
        }
    }

    public function index(){
        $this->view->display();
    }


    //我的订单
    public function order_list(){
        //订单基本数据表
        $order=$this->model->pdo_sel("select * from sh_order where m_id = '{$_SESSION['Home']['Member']['id']}' and stat !=3",2);
        //订单详情数据
        foreach($order as &$v){
            $v['array']=$this->model->pdo_sel("select s.*,g.name,g.img,p.gname from sh_order_s as s join sh_goods as g on s.g_id = g.id join sh_goods_g as p on s.gg_id = p.id where s.o_id = '{$v['id']}'",2);
        }
        $this->view->assign('order',$order);
        $this->view->display();
    }

    //订单详情
    public function order_msg(){
        $id=$_GET['id'];
        $order=$this->model->pdo_sel("select * from sh_order where id = '$id'",1);
        //订单详情数据
        $order['array']=$this->model->pdo_sel("select s.*,g.name,g.img,p.gname from sh_order_s as s join sh_goods as g on s.g_id = g.id join sh_goods_g as p on s.gg_id = p.id where s.o_id = '{$order['id']}'",2);
        //地址
        $order['path']=json_decode($order['path'],true);
        $this->view->assign('v',$order);
        $this->view->display();
    }

    //订单操作
    public function order_upd(){
        $id=$_GET['id'];

        if($this->model->pdo_upd("sh_order",array('stat'=>$_GET['stat'])," where id = $id limit 1")){
            $this->success('操作成功！',"Member",'order_list');
        }else{
            $this->success('操作失败！',"Member",'order_list');
        }

    }

    //查看物流
    public function ckwl(){
        $id=$_GET['id'];
        $order=$this->model->pdo_sel("select * from sh_order where id = $id");
        $url="http://www.kuaidi100.com/query?type={$order['wl_n']}&postid={$order['wl_h']}";

        $str=file_get_contents($url); //请求接口
        $arr=json_decode($str,true); //物流数据

        $this->view->assign('arr',$arr);
        $this->view->display();
    }

    //我的收藏
    public function like(){
        $arr=$this->model->pdo_sel("select l.*,g.name,g.img from sh_like as l join sh_goods as g on l.g_id = g.id where m_id = '{$_SESSION['Home']['Member']['id']}'",2);
        $this->view->assign('arr',$arr);
        $this->view->display();
    }

}